﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ThanhTu.GNC.Media.KQXS.DataAccess.DO;
using Oracle.ManagedDataAccess.Client;
using System.Data;

namespace ThanhTu.GNC.Media.KQXS.DataAccess.DAL
{
    public class PredictedDAL : BaseDAL
    {
        public PredictedDAL() : base() { }
        public int SavePredicted(PredictedDO vPredictedDO)
        {
            using (OracleCommand oraComm = new OracleCommand())
            {
                oraComm.CommandType = CommandType.StoredProcedure;
                oraComm.CommandText = "PREDICTED_PKG.SAVEPREDICTED";
                OracleParameter oraParam = null;

                oraParam = new OracleParameter("IN_PREDICTED_DATE", OracleDbType.Date);
                oraParam.Value = vPredictedDO.Predicted_date;
                oraComm.Parameters.Add(oraParam);

                oraParam = new OracleParameter("IN_PROVINCE_ID", OracleDbType.Varchar2);
                oraParam.Value = vPredictedDO.Province_id;
                oraComm.Parameters.Add(oraParam);

                oraParam = new OracleParameter("IN_NUMBER_PREDICTED", OracleDbType.Varchar2);
                oraParam.Value = vPredictedDO.Number_predicted;
                oraComm.Parameters.Add(oraParam);

                oraParam = new OracleParameter("IN_STYLEPREDICTED", OracleDbType.Int32);
                oraParam.Value = vPredictedDO.Stylepredicted_Id;
                oraComm.Parameters.Add(oraParam);

                oraParam = new OracleParameter("OUTRETURN", OracleDbType.Int32);
                oraParam.Direction = ParameterDirection.Output;
                oraComm.Parameters.Add(oraParam);
                int result = ExecuteNoneQuery(oraComm);

                if (!Convert.IsDBNull(oraComm.Parameters["OUTRETURN"]))
                { result = Convert.ToInt32(oraComm.Parameters["OUTRETURN"].Value.ToString()); }

                oraComm.Dispose();
                oraParam = null;

                return result;
            }
        }
        public DataTable GetPredicted(DateTime Predicted_date, string provinceID, string style)
        {
            using (OracleCommand oraComm = new OracleCommand())
            {
                oraComm.CommandType = CommandType.StoredProcedure;
                oraComm.CommandText = "PREDICTED_PKG.GETPREDICTED";
                OracleParameter oraParam = null;

                oraParam = new OracleParameter("IN_PREDICTED_DATE", OracleDbType.Date);
                oraParam.Value = Predicted_date;
                oraComm.Parameters.Add(oraParam);

                oraParam = new OracleParameter("IN_PROVINCE_ID", OracleDbType.Varchar2);
                oraParam.Value = provinceID;
                oraComm.Parameters.Add(oraParam);

                oraParam = new OracleParameter("IN_STYLEPREDICTED", OracleDbType.Int32);
                oraParam.Value = style;
                oraComm.Parameters.Add(oraParam);

                oraParam = new OracleParameter("OUTRETURN", OracleDbType.RefCursor);
                oraParam.Direction = ParameterDirection.Output;
                oraComm.Parameters.Add(oraParam);

                using (DataSet ds = GetDataSet(oraComm))
                {
                    DataTable dt = null;

                    if (ds != null)
                    {
                        if (ds.Tables.Count > 0)
                        {
                            dt = ds.Tables[0];

                        }

                        ds.Dispose();
                    }

                    oraComm.Dispose();
                    oraParam = null;

                    return dt;
                }
            }
        }
        public DataTable GetALLPredicted(DateTime Predicted_date, string provinceID, string style)
        {
            using (OracleCommand oraComm = new OracleCommand())
            {
                oraComm.CommandType = CommandType.StoredProcedure;
                oraComm.CommandText = "PREDICTED_PKG.GetALLPredicted";
                OracleParameter oraParam = null;

                oraParam = new OracleParameter("IN_PREDICTED_DATE", OracleDbType.Date);
                oraParam.Value = Predicted_date;
                oraComm.Parameters.Add(oraParam);

                oraParam = new OracleParameter("IN_PROVINCE_ID", OracleDbType.Varchar2);
                oraParam.Value = provinceID;
                oraComm.Parameters.Add(oraParam);

                oraParam = new OracleParameter("IN_STYLEPREDICTED", OracleDbType.Int32);
                oraParam.Value = style;
                oraComm.Parameters.Add(oraParam);

                oraParam = new OracleParameter("OUTRETURN", OracleDbType.RefCursor);
                oraParam.Direction = ParameterDirection.Output;
                oraComm.Parameters.Add(oraParam);

                using (DataSet ds = GetDataSet(oraComm))
                {
                    DataTable dt = null;

                    if (ds != null)
                    {
                        if (ds.Tables.Count > 0)
                        {
                            dt = ds.Tables[0];

                        }

                        ds.Dispose();
                    }

                    oraComm.Dispose();
                    oraParam = null;

                    return dt;
                }
            }
        }
    }
}
